package com.comac.tasks.manager.app;

import com.alibaba.cola.dto.Response;
import com.comac.tasks.manager.app.domain.gateway.TasksManagerGateway;
import com.comac.tasks.manager.app.dto.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TasksManagerAppApplication.class})
public class TestDemo {

    @Resource
    private TasksManagerGateway tasksManagerGateway;
    @Test
    public void testBatchInsert(){
        TasksManagerBatchInsertDTO batchInsertDTO = new TasksManagerBatchInsertDTO();
        List <TasksManagerBatchDTO>list = new ArrayList();

        for(int i = 0 ;i<5;i++){
            TasksManagerBatchDTO tasksManagerDTO = new TasksManagerBatchDTO();;
            tasksManagerDTO.setProcessInstanceName("实例名字");
            Map map = new HashMap();
            map.put("type","ewewewwew");
            tasksManagerDTO.setFieldArea(map);
            tasksManagerDTO.setNodeCode("344444");
            tasksManagerDTO.setTasksContent("test-666666666666666");
            tasksManagerDTO.setTaskInstanceId("368237df951811ec9f9100163e0e9474");
            tasksManagerDTO.setProcessInstanceId("35b2d9c2951811ec9f9100163e0e9475");
            tasksManagerDTO.setOperator("33333"+i);
            list.add(tasksManagerDTO);
        }
        batchInsertDTO.setTasksManagerDTOS(list);


        try {
            tasksManagerGateway.batchInsert(batchInsertDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void testInsert(){
        TasksManagerDTO tasksManagerDTO=new TasksManagerDTO();
            tasksManagerDTO.setProcessInstanceName("实例名字");
            Map map = new HashMap();
            map.put("type","ewewewwew");
            tasksManagerDTO.setFieldArea(map);
            tasksManagerDTO.setNodeCode("344444");
            tasksManagerDTO.setTasksContent("test-666666666666666");
            tasksManagerDTO.setTaskInstanceId("368237df951811ec9f9100163e0e9474");
            tasksManagerDTO.setProcessInstanceId("35b2d9c2951811ec9f9100163e0e9475");
            tasksManagerDTO.setOperator("33333");


        try {
            tasksManagerGateway.insert(tasksManagerDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * {
     *   "flag": false,
     *   "operator": "",
     *   "operatorName": "",
     *   "processInstanceIds": [
     *    "55a2045371ea11ec998200163e26d929"
     *   ],
     *   "processNodeStatus": "END",
     *   "status": "",
     *   "taskInstanceIds": [
     *     ""
     *   ],
     *   "type": "01"
     * }
     */
    @Test
    public void testupdate(){
        TasksManagerQry qry = new TasksManagerQry();
        qry.setPageSize(10);
        qry.setPageNum(2);
        qry.setCreator("100086");
        //PageResponse pageResponse1 = tasksManagerGateway.selectPage(qry);
        PageResponse pageResponse = tasksManagerGateway.selectPageByCreator(qry);
        System.out.println(pageResponse);
    }


    @Test
    public void testUpdateStatus(){
        try {
            TasksManagerUpDTO tasksManagerUpDTO=new TasksManagerUpDTO();
            tasksManagerUpDTO.setFlag(true);
            tasksManagerUpDTO.setProcessNodeStatus("ROLLBACK");
            tasksManagerUpDTO.setType("02");
            tasksManagerUpDTO.setStatus("DONE");
            List <String>list = new ArrayList();
            list.add("4f976310488b11ef8ffb0ad144eacaa4");
            tasksManagerUpDTO.setTaskInstanceIds(list);
            Response response = tasksManagerGateway.updateStatus(tasksManagerUpDTO);
            System.out.println(response);
        }
        catch (Exception exception){

        }

    }

}
